package com.aptemo.webetek.server.handlers;

import java.util.ArrayList;

import com.aptemo.webetek.client.commands.Action;
import com.aptemo.webetek.client.commands.impl.GetTeamsAction;
import com.aptemo.webetek.client.commands.responses.ListResponse;
import com.aptemo.webetek.client.exceptions.BackendException;
import com.aptemo.webetek.server.datastore.DataStoreAPI;
import com.aptemo.webetek.shared.TeamBean;

public class TeamsHandler
		extends ActionHandler<GetTeamsAction, ListResponse<TeamBean>>
{

	public TeamsHandler(DataStoreAPI service)
	{
		super(service);
	}

	public Class<? extends Action<?>> getActionType()
	{
		return GetTeamsAction.class;
	}

	@Override
	public ListResponse<TeamBean> invoke(GetTeamsAction action) throws BackendException
	{
		ArrayList<TeamBean> bean = (ArrayList<TeamBean>) dataService.getTeams(action.getNameFilter(), action.isPublic(), action.getOrder());
		return new ListResponse<TeamBean>(bean);
	}

}
